import { ref } from 'vue'
import { defineStore } from 'pinia'

const hanldeLocal = (bol, key): void => {
  if (bol) {
    localStorage.setItem(key, '1')
  } else {
    localStorage.removeItem(key)
  }
}

export const useAppStore = defineStore('app', () => {
  const _isMipai = localStorage.getItem('isMipai')

  const isMipai = ref(_isMipai === '1')

  const setIsMipai = () => {
    isMipai.value = !isMipai.value

    hanldeLocal(isMipai.value, 'isMipai')
  }

  const isProBet = ref(true)

  const setIsProBet = async (_isPropBet: boolean) => {
    isProBet.value = _isPropBet
  }

  return {
    isProBet,
    setIsProBet,
    setIsMipai,
    isMipai,
  }
})
